<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>


        <ui:composition template="./../../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <h:form id="form" prependId="false">
                    <p:dataTable var="deliveryOrders"   widgetVar="carsTable" value="#{generateOrdersManagedBean.getDeliveryOrders()}" emptyMessage="No records found with given criteria">  

                        <f:facet name="header">  
                            <p:outputPanel>  
                                <h:outputText value="Search all fields:" />  
                                <p:inputText id="globalFilter" onkeyup="carsTable.filter()" style="width:150px" />  
                            </p:outputPanel>  
                        </f:facet>  
                      

                        <p:column  filterBy="#{deliveryOrders.id}"
                                   headerText="Delivery Order Id" 
                                   filterMatchMode="exact">  
                            <h:outputText value="#{deliveryOrders.id}" />  
                        </p:column>  

                        <p:column filterBy="#{deliveryOrders.parentSalesOrder.id }"  
                                  headerText="Sales Order Id"    filterMatchMode="exact">  
                            <h:outputText value="#{deliveryOrders.parentSalesOrder.id }" />  
                        </p:column>  

                        <p:column  filterBy="#{deliveryOrders.generateDate}"   
                                   headerText="Generate Date"  

                                   filterMatchMode="contains">  

                            <h:outputText value="#{deliveryOrders.generateDate}" >
                                <f:convertDateTime pattern="yyyy.MMMMM.dd"/>
                            </h:outputText>
                        </p:column>  

                        <p:column filterBy="#{deliveryOrders.deliveryDate }"  
                                  headerText="Delivery Date"    filterMatchMode="contains">  
                            <h:outputText value="#{deliveryOrders.deliveryDate}" >
                                <f:convertDateTime pattern="yyyy.MMMMM.dd"/>
                            </h:outputText>
                        </p:column> 
                           <p:column filterBy="#{deliveryOrders.shippingAddress.streetName}"  
                                  headerText="Delivery Location"    filterMatchMode="contains">  
                            <h:outputText value="#{deliveryOrders.shippingAddress.streetName}," />
                            <h:outputText value="#{deliveryOrders.shippingAddress.city}"/>
                        </p:column>

                        <p:column style="width:65px;">
                            <f:facet name="header">Order Detail</f:facet>

                            <p:commandButton update=":form:display" oncomplete="viewDetailsDialog.show()" image="ui-icon ui-icon-search" title="View"  >
                                <f:setPropertyActionListener value="#{deliveryOrders}" target="#{generateOrdersManagedBean.selectedForView}" />  

                            </p:commandButton>
                        </p:column>  


                        <p:column>
                            <p:commandButton value="Generate Orders" action="#{generateOrdersManagedBean.generateOrders(deliveryOrders)}" image="ui-icon ui-icon-check" title="Select"    >
                          
                            </p:commandButton>
                        </p:column>

                    </p:dataTable>  
                    <br />

                    <p:dialog header="Order Detail" widgetVar="viewDetailsDialog" resizable="false" id="viewDetails" showEffect="fade" hideEffect="explode" modal="true" width="700">  

                        <h:panelGrid id="display" cellpadding="0" style="margin:0 auto;"> 

                            <p:dataTable id="recordDetail" dynamic="true"   value="#{generateOrdersManagedBean.selectedForView.deliveryOrderLineItems}" var ="lineItems" >

                                <p:column>
                                    <f:facet name="header">Product Name</f:facet>
                                    #{lineItems.product.productName}
                                </p:column>

                                <p:column>
                                    <f:facet name="header">Required Quantity</f:facet>
                                    <h:outputText value="#{lineItems.quantity}"/> 
                                </p:column> 

                               
                                  <p:column>
                                    <f:facet name="header">Cum Amount</f:facet>
                                    #{lineItems.cumAmount}
                                </p:column> 
                                
                                 
                            </p:dataTable>
               </h:panelGrid>
                    </p:dialog>
                </h:form>
            </ui:define>
        </ui:composition>



    </body>
</html>
